//https://blog.csdn.net/zl1zl2zl3/article/details/81357146
import { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Button,
    Modal,
} from 'antd';

const FormItem = Form.Item;
const { Option } = Select;



//查看表单
@Form.create()
class ViewForm extends PureComponent {
    static defaultProps = {
        handleViewModalVisible: () => {},
    values: {},
};

constructor(props) {
    super(props);

    this.state = {
        formVals: {
            id: props.values.id,
            name: props.values.name,
            enname: props.values.enname,
            memo: props.values.memo,
            display: props.values.display,
        },
    };


}



renderContent = (formVals) => {
    const { form } = this.props;

    return (
        <Form  layout="vertical" hideRequiredMark>



                <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


                    <Col  md={12} sm={24}>
	                    <FormItem  label="名称">
	                        {form.getFieldDecorator('name', {
	                        rules: [{ required: true, message: '请输入至少五个字符的名称！', min: 5 }],
	                        initialValue: formVals.name,
	                        })(<Input  readOnly placeholder="请输入" />)}
	                    </FormItem>
                    </Col>



                    <Col  md={12} sm={24}>
	                    <FormItem  label="英文名称">
	                        {form.getFieldDecorator('enname', {
	                        rules: [{ required: true, message: '请输入至少五个字符的英文名称！', min: 5 }],
	                        initialValue: formVals.enname,
	                        })(<Input  readOnly placeholder="请输入" />)}
	                    </FormItem>
                    </Col>


                </Row>

                <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


                   	<Col  md={12} sm={24}>
	                    <FormItem label="是否显示">
	                        {form.getFieldDecorator('display',{
	                        	initialValue: formVals.display + '',
	                        })(
	                             <Select placeholder="请选择" style={{ width: '100%' }}>
	                                    <Option value="1">是</Option>
	                                     <Option value="0">否</Option>
	                             </Select>
	                        )}
	                    </FormItem>
                    </Col>



                    <Col  md={12} sm={24}>
	                    <FormItem  label="备注">
	                        {form.getFieldDecorator('memo', {
	                        rules: [{ required: true, message: '请输入至少五个字符的备注！', min: 5 }],
	                        initialValue: formVals.memo,
	                        })(<Input  readOnly placeholder="请输入" />)}
	                    </FormItem>
                    </Col>
                    
                    
                </Row>

    </Form>
);

};


render() {
    const { viewModalVisible, handleViewModalVisible, values } = this.props;
    const { formVals } = this.state;

    return (
        <Modal
    width={800}
    height={800}
    bodyStyle={{ padding: '32px 40px 48px' }}
    destroyOnClose
    title="查看"
    visible={viewModalVisible}
    onCancel={() => handleViewModalVisible(false, values)}
    footer={<Button key="back" onClick = { () => handleViewModalVisible(false, values) }>取消</Button>}
>

    {this.renderContent(values)}
</Modal>
);
}

}

export default ViewForm;




